----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 4201 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 240
SPELL.m_sName = "Sweeping Strike"
SPELL.m_sToolTip = [[You swing your weapon
					in a sweeping arc, 
					damaging 3 nearby enemies.]]
SPELL.m_sIcon = "devin/blackbetty/spells/blademaster/sweeping_strike.png"
SPELL.m_bRequiresTarget = true
SPELL.m_iManaCost = 30
SPELL.m_iCoolDown = 1
SPELL.m_iSpellType = SPELLTYPE_BLADEMASTER

---------------------------------------------------------------------------------------

local range = 100

function SPELL:Cast( pl, target )
	local target = nil
	local weapon = nil
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
		target = pl:GetNetworkedEntity("Target")
	else
		target = pl.Target
	end
	if(target && target:IsValid() && target != pl ) then
		pl.InSpellAnimation = true
		pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE2)
		pl:EmitSound("devin/blackbetty/weapons/swing/swing_hit.wav", 100, 100+math.random(-10,10))
			timer.Simple(0.25, function()
				if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
					pl:EmitSound("devin/blackbetty/weapons/Swipe.wav", 160, 80)
					local whirlRadius = ents.FindInSphere(pl:GetPos(), 240)
					local swingcounter = 0
					if(SERVER)then
						for i, s in pairs(whirlRadius)do
							if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm" and s:Health() > 0)then
								swingcounter = swingcounter + 1
								local dmginfo = DamageInfo()
									dmginfo:SetDamage(math.random(weapon.MinWeaponDamage, weapon.MaxWeaponDamage)*2) --50 damage
									dmginfo:SetDamageType( DMG_SLASH ) --Bullet damage
									dmginfo:SetAttacker( pl ) --First player found gets credit
									dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) ) --Launch upwards
								s:EmitSound("devin/blackbetty/weapons/GougeTarget.wav", 100, 100+math.random(-10,10))
								s:TakeDamageInfo( dmginfo )
								ParticleEffect( "pummel_hit", s:GetPos() + Vector(0, 0, 46) + (s:GetAngles():Forward()*6), Angle(0,0,0), pl )
								ParticleEffect( "player_blood", s:GetPos() + Vector(0, 0, 46) + (s:GetAngles():Forward()*6), Angle(0,0,0), pl )
								if SERVER then
									s:SetVelocity(((pl:GetPos()- Vector(0, 0, 40)) - s:GetPos())*-2)
								end	
								if(swingcounter == 3)then
									break
								end
							end
						end
					end
				end
			end)
		timer.Simple(0.4, function()
				pl.InSpellAnimation = false
				pl:SetNWBool("Casting", false)
				pl:SetNWBool("Casted", false)
		end)
	end
end



